package com.cinema.model;

import java.util.Objects;

/**
 * 电影类
 * 
 * @author Cinema Management System
 * @version 1.0.0
 */
public class Movie {
    
    /**
     * 电影ID
     */
    private String movieId;
    
    /**
     * 片名
     */
    private String title;
    
    /**
     * 导演
     */
    private String director;
    
    /**
     * 主演
     */
    private String actors;
    
    /**
     * 剧情简介
     */
    private String description;
    
    /**
     * 时长（分钟）
     */
    private int duration;
    
    /**
     * 评分（0-10分）
     */
    private double rating;
    
    /**
     * 是否正在上映
     */
    private boolean isShowing;
    
    /**
     * 默认构造函数
     */
    public Movie() {
        this.isShowing = true;
        this.rating = 0.0;
    }
    
    /**
     * 构造函数
     * 
     * @param movieId 电影ID
     * @param title 片名
     * @param director 导演
     * @param actors 主演
     * @param description 剧情简介
     * @param duration 时长
     * @param rating 评分
     */
    public Movie(String movieId, String title, String director, String actors, 
                 String description, int duration, double rating) {
        this();
        this.movieId = movieId;
        this.title = title;
        this.director = director;
        this.actors = actors;
        this.description = description;
        this.duration = duration;
        this.rating = rating;
    }
    
    /**
     * 验证评分是否有效
     * 
     * @param rating 评分
     * @return 是否有效
     */
    public static boolean isValidRating(double rating) {
        return rating >= 0.0 && rating <= 10.0;
    }
    
    /**
     * 设置评分
     * 
     * @param rating 评分
     * @throws IllegalArgumentException 如果评分无效
     */
    public void setRating(double rating) {
        if (!isValidRating(rating)) {
            throw new IllegalArgumentException("评分必须在0-10之间");
        }
        this.rating = rating;
    }
    
    // Getter和Setter方法
    public String getMovieId() {
        return movieId;
    }
    
    public void setMovieId(String movieId) {
        this.movieId = movieId;
    }
    
    public String getTitle() {
        return title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getDirector() {
        return director;
    }
    
    public void setDirector(String director) {
        this.director = director;
    }
    
    public String getActors() {
        return actors;
    }
    
    public void setActors(String actors) {
        this.actors = actors;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public int getDuration() {
        return duration;
    }
    
    public void setDuration(int duration) {
        if (duration <= 0) {
            throw new IllegalArgumentException("电影时长必须大于0");
        }
        this.duration = duration;
    }
    
    public double getRating() {
        return rating;
    }
    
    public boolean isShowing() {
        return isShowing;
    }
    
    public void setShowing(boolean showing) {
        isShowing = showing;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        Movie movie = (Movie) obj;
        return Objects.equals(movieId, movie.movieId);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(movieId);
    }
    
    @Override
    public String toString() {
        return "Movie{" +
                "movieId='" + movieId + '\'' +
                ", title='" + title + '\'' +
                ", director='" + director + '\'' +
                ", actors='" + actors + '\'' +
                ", duration=" + duration + "分钟" +
                ", rating=" + rating + "分" +
                ", isShowing=" + isShowing +
                '}';
    }
} 